package leetcode.code1022;

import leetcode.IDebug;
import leetcode.helper.tree.TreeNode;

public class Solution implements IDebug {

	public int sumRootToLeaf(TreeNode root) {
		return this.sumRootToLeaf(root, 0);
	}

	private int sumRootToLeaf(TreeNode root, int num) {
		int ans = 0;
		num <<= 1;
		num |= root.val;
		if (root.left == null && root.right == null) {
			return num;
		}
		if (root.left != null) {
			ans += this.sumRootToLeaf(root.left, num);
		}
		if (root.right != null) {
			ans += this.sumRootToLeaf(root.right, num);
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
